Page({

  data: {
    block: "none",
    items: [],
    host: wx.getStorageSync('host'),

    startX: 0, //开始坐标

    startY: 0

  },

  onLoad: function(e) {
    var that = this;
    let url = wx.getStorageSync('url');
    let authorization = wx.getStorageSync('authorization');
      wx.request({
        url: url + "/v1/user/collection",
        data: {
        },
        method: "get",
        header: {
          'content-type': 'json',
          'authorization': authorization,
          'openid': wx.getStorageSync('openid')
        },
        success: function(res) {
          var list = []
          list = res.data.data.mpCollections
          if (list == "") {
            that.setData({
              block: "block"
            })
          } else {
            that.setData({
              block: "none"
            })
          }
          for (var j = 0; j < list.length; j++) {
            if (list[j].type == 1) {
              list[j].ctype = '求助'
            } else if (list[j].type == 2) {
              list[j].ctype = '闲置'

            } else if (list[j].type == 3) {
              list[j].ctype = '兼职'

            } else if (list[j].type == 4) {
              list[j].ctype = '租房'

            } else if (list[j].type == 5) {
              list[j].ctype = '寻物'

            } else if (list[j].type == 6) {
              list[j].ctype = '招领'

            } else if (list[j].type == 7) {
              list[j].ctype = '投稿'

            } else if (list[j].type == 8) {
              list[j].ctype = '表白'

            }
            list[j].image = list[j].image.split(",")
            list[j].gmtCreated = list[j].gmtCreated.slice(5)
          }
          that.setData({
            items: list
          })

        }
      })
    },

  //手指触摸动作开始 记录起点X坐标
  onPullDownRefresh() {
    var that = this
    var url = wx.getStorageSync('url')
    var authorization = wx.getStorageSync('authorization')
    wx.request({
      url: url + "/v1/user/collection",
      data: {
      },
      method: "get",
      header: {
        'content-type': 'json',
        'authorization': authorization,
        'openid': wx.getStorageSync('openid')
      },
      success: function (res) {
        var list = []
        list = res.data.data.mpCollections
        if (list == "") {
          that.setData({
            block: "block"
          })
        } else {
          that.setData({
            block: "none"
          })
        }
        for (var j = 0; j < list.length; j++) {
          if (list[j].type == 1) {
            list[j].ctype = '求助'
          } else if (list[j].type == 2) {
            list[j].ctype = '闲置'

          } else if (list[j].type == 3) {
            list[j].ctype = '兼职'

          } else if (list[j].type == 4) {
            list[j].ctype = '租房'

          } else if (list[j].type == 5) {
            list[j].ctype = '寻物'

          } else if (list[j].type == 6) {
            list[j].ctype = '招领'

          } else if (list[j].type == 7) {
            list[j].ctype = '投稿'

          } else if (list[j].type == 8) {
            list[j].ctype = '表白'

          }
          list[j].image = list[j].image.split(",")
          list[j].gmtCreated = list[j].gmtCreated.slice(5)
        }
        that.setData({
          items: list
        })

      }
    })

    wx.stopPullDownRefresh()

  },
 

  //删除事件

  reply: function(e) {
    console.log(e)
    let url = wx.getStorageSync('url');
    wx.request({
      url: url + "/v1/article/collection/%7Bid%7D?id=" + e.currentTarget.dataset.ids,
      data: {
      },
      method: "DELETE",
      header: {
        'content-type': 'json',
        'authorization': wx.getStorageSync('authorization'),
        'openid': wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
      }
    })

    this.data.items.splice(e.currentTarget.dataset.index, 1)

    this.setData({

      items: this.data.items

    })

  },
  collection(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '/pages/Details/index?id=' + e.currentTarget.dataset.id,
    })
  },

})